package com.framework.base.taglib;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import net.fckeditor.FCKeditor;

import org.apache.log4j.Logger;

import com.framework.base.util.LoggerUtil;

/**
 * @CopyrightAll right reserved
 * @author 作者：Create by www.51wuxia.com
 * @description 类说明
 * 
 */
public class FCKeditorTag extends BodyTagSupport {
	private String elName = "";
	private String defaultValue = "";
	private String height;
	static Logger logger=Logger.getLogger(FCKeditorTag.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String getElName() {
		return elName;
	}

	public void setElName(String elName) {
		this.elName = elName;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	@Override
	public int doEndTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext
				.getRequest(); // 取得request对象
		// 初始化参数

		JspWriter out = pageContext.getOut();
		StringBuffer sb = new StringBuffer();
		sb.append("<script type='text/javascript'>");
		sb.append("function FCKeditor_OnComplete(editorInstance) {");
		sb.append("	window.status = editorInstance.Description;}");
		sb.append("</script>");
		FCKeditor fckEditor = new FCKeditor(request, this.getElName());
		fckEditor.setValue(this.getDefaultValue());
		fckEditor.setBasePath(request.getContextPath()+"/common/fckeditor");
		if (this.getHeight() != null && !this.getHeight().equals("")) {
			fckEditor.setHeight(this.getHeight());
		}
		try {
			out.println(fckEditor);
		} catch (IOException e) {
			LoggerUtil.logError(e, logger, "fck写标签失败");
		}
		return EVAL_PAGE;

	}
}
